﻿function SetSelect(bbool)
{
	var sels = document.getElementsByTagName("select");
	for(var i=0;i<sels.length;i++)
	{
		obj = sels[i];
		if(bbool)
		{obj.style.display = '';}
		else
		{
		obj.style.display = 'none';
		}
	}
}
function GetProcess()
{
     var url = "/files/uploFileProcBarDo.aspx?Process=1&LongxinUploadGUID="+document.getElementById("LongxinUploadGUID").value;
     document.getElementById("ifFileUploProcBar").src = "";
     document.getElementById("ifFileUploProcBar").src = url;
}
function Save()
{
    var iframeCon = document.getElementById("divFrame");
    iframeCon.innerHTML = "<iframe name='ifFileUploProcBar' id='ifFileUploProcBar' width='0px' height='0px'src=''></iframe>";
    iframeCon.innerHTML += "<iframe name='ifFileUploSucc' id='ifFileUploSucc' width='0px' height='0px'src=''></iframe>";
    //document.getElementById("upload").disabled = "disabled";
    document.getElementById("LongxinUploadGUID").value = Math.random();
    document.getElementById("divFileUploProcBar").style.display = "";
    document.getElementById("Form1").submit();
    GetProcess();
    SetSelect(false);
}
function SetProcessDiv(str)
{
  if(str=="C")
  {
      HideProcess();
  }
  else if(str=="ML")
  {
     HideProcess();
     document.getElementById("ErrorMessageDiv1").style.display = "";
  }
  else if(str.indexOf("NL")==0)
  {
    //alert(str);
    HideProcess();
    document.getElementById("ErrorMessageDiv2").style.display = "";
  }
  else
  {
    document.getElementById("divFileUploProcBar").innerHTML = "<div style='Z-INDEX: 99; MARGIN:0 auto; WIDTH: 500px; POSITION: relative; TOP: 0px; height:0px'>"+str+"</div>";
  }
}

function HideProcess()
{
    document.getElementById("divFileUploProcBar").style.display = "none";
    document.getElementById("divFileUploProcBar").innerHTML = "";
    document.getElementById("ifFileUploProcBar").src = "";
}

function SaveFinish(str)
{
  HideProcess();
  //document.getElementById("upload").disabled = "";
  var filesize = document.getElementById('uploadFileSize').value;
  if(str=="ML")
  {
    document.getElementById("ErrorMessageDiv1").style.display = "";
  }
  else if(str.indexOf("NL")==0)
  {
    //alert(str);
    document.getElementById("ErrorMessageDiv2").style.display = "";
  }
  else if(str=="-1"||str=="-2")
  {
    document.getElementById("ErrorMessageDiv3").style.display = "";
  }
  else
  {
    //window.location.href="/files/uploadSuccess.htm?fz=" + filesize;
    window.location.href="/files/mydocs.htm";
  }
  
} 
function load_func()
{
    window.onresize=JustDiv;
    window.onscroll=JustDiv;
    JustDiv();	
}
function JustDiv()
{
    var scrollPos; 
    if (typeof window.pageYOffset != 'undefined') 
    { 
       scrollPos = window.pageYOffset; 
    } 
    else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
    { 
       scrollPos = document.documentElement.scrollTop; 
    } 
    else if (typeof document.body != 'undefined')
    { 
       scrollPos = document.body.scrollTop; 
    } 
	document.getElementById("divFileUploProcBar").style.top = (scrollPos)+"px";
    document.getElementById("ErrorMessageDiv1").style.top = (scrollPos)+"px";
    document.getElementById("ErrorMessageDiv2").style.top = (scrollPos)+"px";
    document.getElementById("ErrorMessageDiv3").style.top = (scrollPos)+"px";
}
function UploadFile()
{
    if(__P_M==""){$Login$();return;}
    var isValid = true;
    
    var data_error = $('span_data_error');
    var data_error1 = $('span_data_error1');    
    var title_error = $('span_title_error');
    var learn_error = $('span_learn_error');
    var using_error = $('span_using_error');
    
    var data = $('file_data');
    var title = $('text_title');
    var learn = $('slct_learn');
    var using = $('slct_using');
    
    data_error.style.display = 'none';
    data_error1.style.display = 'none';
    title_error.style.display = 'none';
    learn_error.style.display = 'none';
    using_error.style.display = 'none';
    
    if(data.value == ''){
        data_error.style.display = 'block';
        isValid = false;
    }
    if(title.value == ''){
        title_error.style.display = 'block';
        isValid = false;
    }
    if(learn.value == ''){
        learn_error.style.display = 'block';
        isValid = false;
    }
    if(using.value == ''){
        using_error.style.display = 'block';
        isValid = false;
    }
     if(data.value == ''){
        data_error.style.display = 'block';
        isValid = false;
    }else{
    switch(data.value.substr(data.value.lastIndexOf('.') + 1))
    {
        case 'doc':
        break;
        case 'ppt':
        break;
        case 'pps':
        break;
        case 'xls':
        break;
        case 'pdf':
        break;
        case 'ps':
        break;
        case 'txt':
        break;
        case 'rtf':
        break;
        default:
            data_error1.style.display = 'block';
            isValid = false;
        break;
    }}
    if(isValid)
    {
        Save();
    }
}
